import { imgfrom } from '@/config/config'
// import { getImgSrc, filterIds, filterList, genArrOfIds } from 'common/js/tools'
export function debounce (fn, delay) {
  let timer = null
  return function (...args) {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  }
}

export function getImgSrc (remoteImgUrl) {
  if (!remoteImgUrl) return ''
  let articlePic = remoteImgUrl
  if (!(articlePic.indexOf('http') > -1)) {
    articlePic = 'http:' + articlePic
  }
  return imgfrom.url + '/apizdm/getimg?url=' + articlePic
}

export function filterIds (newArr, oldArr) { // 保留newArr中，所有项目都与oldArr不同
  return newArr.filter((id) => {
    return !(oldArr.indexOf(id) > -1)
  })
}

export function filterList (arrIds, arrItems) { // 保留arrItems，其中保留arrItems.article_id出现在arrIds中的才保留
  return arrItems.filter((item) => {
    return arrIds.indexOf(item.article_id) > -1
  })
}

export function genArrOfIds (arr) {
  let tmpArr = []
  arr.forEach((item) => {
    tmpArr.push(item.article_id)
  })
  return tmpArr
}
